package svc

import (
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"mall/app/product/cmd/rpc/internal/config"
	"mall/app/product/model"
)

type ServiceContext struct {
	Config                config.Config
	CategoryModel         model.PmsCategoryModel
	BrandModel            model.PmsBrandModel
	AttrGroupModel        model.PmsAttrGroupModel
	AttrModel             model.PmsAttrModel
	CategoryBrandModel    model.PmsCategoryBrandRelationModel
	SkuInfoModel          model.PmsSkuInfoModel
	SkuImagesModel        model.PmsSkuImagesModel
	SpuInfoModel          model.PmsSpuInfoModel
	SpuInfoDescModel      model.PmsSpuInfoDescModel
	ProductAttrValueModel model.PmsProductAttrValueModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	conn := sqlx.NewMysql(c.DataSource)
	return &ServiceContext{
		Config:                c,
		CategoryModel:         model.NewPmsCategoryModel(conn),
		BrandModel:            model.NewPmsBrandModel(conn),
		AttrGroupModel:        model.NewPmsAttrGroupModel(conn),
		AttrModel:             model.NewPmsAttrModel(conn),
		CategoryBrandModel:    model.NewPmsCategoryBrandRelationModel(conn),
		SkuInfoModel:          model.NewPmsSkuInfoModel(conn),
		SkuImagesModel:        model.NewPmsSkuImagesModel(conn),
		SpuInfoModel:          model.NewPmsSpuInfoModel(conn),
		SpuInfoDescModel:      model.NewPmsSpuInfoDescModel(conn),
		ProductAttrValueModel: model.NewPmsProductAttrValueModel(conn),
	}
}
